﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Kaidou.Persister;
using Kaidou.Model;
using System.Collections.Generic;
using Kaidou.Util;
using Kaidou.Bll;

public partial class master_master_union : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoginModel loginModel = ( LoginModel ) Session["loginModel"] ;

        if ( loginModel == null)
        {
            Response.Redirect("../login.aspx");
        }
        else if (!loginModel.isOperator())
        {
            Response.Redirect("../menu.aspx");
        }

        if ("on".Equals(Resources.Resource.kaidou_view_user_clss))
        {
            user_clss_panel.Visible = true;
        }
        else
        {
            user_clss_panel.Visible = false;
        }

        if ("30".Equals(MstUnion.USER_CLSS_OPERATOR))
        {
            loginButton.Visible = true;
        }
        else
        {
            loginButton.Visible = false;
        }

        string area=Resources.Resource.area;
        string[] areaArray=area.Split(',');
        for (int i = 0; i < areaArray.Length;i++ )
        {
            ListItem item=new ListItem();
            item.Value=(i+1)+"";
            item.Text=areaArray[i];
            office_pref_code.Items.Insert(i+1,item);
        }

    }

    protected void login_confirm(object sender, EventArgs e)
    {
        
        //カプセル化オブジェクト
        MstUnion M = new MstUnion();
        MstUnionId MID = new MstUnionId();
        MID.UnionCode = union_code.Text;
        MID.BranchCode = 0;
        M.Id = MID;
        M.OfficeAddress = office_address.Text;
        M.OfficeCity = office_city.Text;
        M.OfficeEmail = office_email.Text;
        M.OfficeFax = office_fax.Text;
        M.OfficeKana = office_kana.Text;
        M.OfficeName = office_name.Text;
        M.OfficePrefCode = short.Parse(office_pref_code.Text);
        M.OfficeTel = office_tel.Text;
        M.OfficeZipNo = office_zip_no1.Text + office_zip_no2.Text;
        M.OfficeZipNo1 = office_zip_no1.Text;
        M.OfficeZipNo2 = office_zip_no2.Text;
        M.Password = StringUtil.getRandomPassword();
        M.DaihyoName = daihyo_name.Text;
        M.DaihyoKana = daihyo_kana.Text;
        M.RegDate = System.DateTime.Now;
        M.TantoKana = tanto_kana.Text;
        M.TantoName = tanto_name.Text;
        M.TraderRegNo = trader_reg_no1.Text + trader_reg_no2.Text;
        M.TraderRegNo1 = trader_reg_no1.Text;
        M.TraderRegNo2 = trader_reg_no2.Text;

        M.UpdDate = System.DateTime.Now;
        M.UpdUnionCode =  (string)Session["Login_Union_code"];
        M.UpdBranchCode = (short)Session["Login_Branch_code"];

        M.UserClss = (user_clss1.Checked ? 10 : user_clss2.Checked ? 20 : 30)+"";
        M.CancelRestFlg = StringUtil.CANCEL_REST_FLG_NORMAL;
        M.UnionSts = StringUtil.STATUS_NORMAL;
        M.UpdFuncId = "insertMasterUnion()";

        //検証
        MST_UnionManager validation = new MST_UnionManager();
        List<string> errorCodeList = validation.checkInsertOrUpdateUnion(M,Resources.Resource.ResourceManager,true);
        msg.Text = ErrorCodeUtil.errorCodeListToHtml(errorCodeList);
     
        if (errorCodeList.Count == 0)
        {
            //ユーザー区分編集機能がOFFなら組合員にする。
            if (!"on".Equals(Resources.Resource.kaidou_view_user_clss))
            {
                M.UserClss = MstUnion.USER_CLSS_KUMIAIIN;
            }
            Session["mstunion"] = M;
            Response.Redirect("master_union_conf.aspx");
        }
        
       
        
    }
}
